package com.chf.springcloud_test_consumer.controller;

import com.chf.springcloud_test_consumer.beans.Depart;
import com.chf.springcloud_test_consumer.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins="*")
@RestController
@RequestMapping("/provider/depart")
public class DepartController {
    @Autowired
    private DepartService service;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Depart depart){
        depart.setDbase("test");
        return service.saveDepart(depart);
    }
    @DeleteMapping("/del/{id}")
    public boolean removeHandle(@PathVariable("id") int id){
        return service.removeDepartById(id);
    }
    @PutMapping("/update")
    public boolean modifyHandle(@RequestBody Depart depart) {
        depart.setDbase("test");
        return service.modifyDepart(depart);
    }
    @GetMapping("/get/{id}")
    public Depart getDepartHandle(@PathVariable("id") int id) {
        return service.getDepartById(id);
    }
    @GetMapping("/list")
    public List<Depart> listAllDepartsHandle(){
        return service.listAllDeparts();
    }
}
